Security News
New Python Packaging Proposal Aims to Solve Phantom Dependency Problem with SBOMs
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
apollo-utilities
Advanced tools
The apollo-utilities package provides a set of utility functions for working with GraphQL data in Apollo Client. These utilities help with tasks such as parsing, transforming, and comparing GraphQL queries and results.
GraphQL Query Parsing
This feature allows you to parse a GraphQL query and extract the operation definition. The code sample demonstrates how to use the `getOperationDefinition` function to parse a query and log the operation definition.
const { getOperationDefinition } = require('apollo-utilities');
const gql = require('graphql-tag');
const query = gql`
query GetUser {
user(id: 1) {
id
name
}
}
`;
const operationDefinition = getOperationDefinition(query);
console.log(operationDefinition);
Deep Equality Check
This feature provides a deep equality check for comparing two objects. The code sample demonstrates how to use the `isEqual` function to compare two nested objects.
const { isEqual } = require('apollo-utilities');
const obj1 = { a: 1, b: { c: 2 } };
const obj2 = { a: 1, b: { c: 2 } };
console.log(isEqual(obj1, obj2)); // true
Query Transformation
This feature allows you to transform a GraphQL query by adding `__typename` fields to it. The code sample demonstrates how to use the `addTypenameToDocument` function to transform a query.
const { addTypenameToDocument } = require('apollo-utilities');
const gql = require('graphql-tag');
const query = gql`
query GetUser {
user(id: 1) {
id
name
}
}
`;
const transformedQuery = addTypenameToDocument(query);
console.log(transformedQuery);
The graphql-tools package provides a set of utilities for building and manipulating GraphQL schemas in JavaScript. It offers functionalities such as schema stitching, schema transformation, and mock data generation. Compared to apollo-utilities, graphql-tools focuses more on schema-related tasks rather than query manipulation.
The graphql-tag package is used to parse GraphQL queries into the standard GraphQL AST format. It is often used in conjunction with Apollo Client to define queries. While graphql-tag focuses on parsing queries, apollo-utilities provides additional functionalities such as query transformation and deep equality checks.
The lodash package is a utility library that provides a wide range of functions for manipulating arrays, objects, and other data types. While it is not specific to GraphQL, lodash offers deep equality checks and other utility functions that can be useful in a GraphQL context. Compared to apollo-utilities, lodash is more general-purpose and not tailored specifically for GraphQL.
FAQs
Utilities for working with GraphQL ASTs
The npm package apollo-utilities receives a total of 567,246 weekly downloads. As such, apollo-utilities popularity was classified as popular.
We found that apollo-utilities demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
Security News
Socket CEO Feross Aboukhadijeh discusses open source security challenges, including zero-day attacks and supply chain risks, on the Cyber Security Council podcast.
Security News
Research
Socket researchers uncover how threat actors weaponize Out-of-Band Application Security Testing (OAST) techniques across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.